unit desktop;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
  Vcl.StdCtrls, Vcl.ExtCtrls, VclTee.TeeGDIPlus, VclTee.TeEngine, VclTee.Series,
  VclTee.TeeProcs, VclTee.Chart, EventBus, Vcl.MPlayer, Vcl.Imaging.pngimage;

type
  TDeskTopForm = class(TForm)
    Chart1: TChart;
    Series1: TLineSeries;
    FlowPanel1: TFlowPanel;
    Chart2: TChart;
    Series2: TPieSeries;
    img1: TImage;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    [Channel('QueryMemoryUsage')]
    procedure QueryMemoryUsage(size: string);
  end;

var
  DeskTopForm: TDeskTopForm;

implementation

{$R *.dfm}

var
  count: Integer;

procedure TDeskTopForm.FormDestroy(Sender: TObject);
begin
  GlobalEventBus.UnregisterForChannels(self);
end;

procedure TDeskTopForm.QueryMemoryUsage(size: string);
begin
  //
  count := count + 1;
  Series1.AddXY(count, StrToInt(size));
  if Series1.count > 100 then
  begin
    Series1.Delete(0);
  end;
  if Series2.count < 5 then
  begin
    var
      cl: Integer := Random(65535);
    if cl < 200 then
    begin
      cl := cl + 200;
    end;
    Series2.Add(cl, 'Tom', cl);

  end;

end;

procedure TDeskTopForm.FormCreate(Sender: TObject);
begin
  count := 0;
  GlobalEventBus.RegisterSubscriberForChannels(self);

end;

initialization

RegisterClass(TDeskTopForm);

finalization

UnRegisterClass(TDeskTopForm);

end.
